package com.demo.modules.mq.rabbit.configuration;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 路由关键字过滤，只支持精确值，可以对消息进行过滤匹配
 *
 * @author MyPC
 */
@Configuration
public class DirectConfiguration {

    /**
     * 创建一个direct类型的交换机
     *
     * @return
     */
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("wr.direct");
    }

    /**
     * 声明一个队列
     *
     * @return
     */
    @Bean
    public Queue queue05() {
        return new Queue("direct.queue05");
    }

    /**
     * 声明一个队列
     *
     * @return
     */
    @Bean
    public Queue queue06() {
        return new Queue("direct.queue06");
    }

    /**
     * 绑定交换机和队列
     *
     * @param directExchange
     * @param queue05
     * @return
     */
    @Bean
    public Binding binding05(DirectExchange directExchange, Queue queue05) {
        //创建绑定关系，并且声明固定过滤字符
        return BindingBuilder.bind(queue05).to(directExchange).with("info");
    }

    /**
     * 绑定交换机和队列
     *
     * @param directExchange
     * @param queue06
     * @return
     */
    @Bean
    public Binding binding06(DirectExchange directExchange, Queue queue06) {
        //创建绑定关系，并且声明固定过滤字符
        return BindingBuilder.bind(queue06).to(directExchange).with("error");
    }
}
